#!/usr/bin/perl -w
use DBI;
use mydb;
use myvideo;
use Digest::MD5;

my_connect();
$sql = "SELECT * FROM t_task WHERE status = 'upload'";

#when file is upload down fetch row from t_task 

$sth = $dbconn->prepare($sql) or die $dbconn->errstr;

$sth->execute() or die "错误: " . $sth->errstr;
 
  while (@data = $sth->fetchrow()) {
 
  $rowid = $data[0];
  $file = $data[5];


  if(! -e $file) { # file isn't exit;

	if(set_task_work_status($rowid, "error", "the file isn't exit!") == 0) {
	
		next;

	}
  }
  else {
	set_task_work_status($rowid, "analyize", "");

	$len = -s $file;

	if($len == 0) {

		set_task_work_status($rowid, "error", "the file is empty!");
		next;
	}

	open(FH, $file ) or die "Can't open '$file': $!";
	binmode(FH);

	$s_size = $len;
	update_task_field($rowid, "size", $len);
	$s_md5 = Digest::MD5->new->addfile(*FH)->hexdigest;
	update_task_field($rowid, "md5", $s_md5);
	set_videoinfo($rowid, $file);
	set_analyize_end_status($rowid);

  }
 
}

my_disconnect();
